/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import entity.Discuss;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import util.DatabaseUtil;

/**
 *
 * @author zhang
 */
public class FindDiscuss {
    public List<Discuss> findDiscussByBookId(int bookId){     //找到某一本书的所有评论
        List<Discuss> list=new ArrayList<>();
        Connection con=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        try{
            con=DatabaseUtil.connect();
            ps=con.prepareStatement("select * from discuss where bookid=?");
            ps.setInt(1,bookId);
            rs=ps.executeQuery();
            while(rs.next()){
                list.add(new Discuss(rs.getInt(1),rs.getInt(2),rs.getInt(3),rs.getString(4)));
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            DatabaseUtil.closeConnection(con, ps,null);
        }
        return list;
    }
}
